package com.wyl.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
  /**
   * getDateStr get a string with format HH:mm:ss from a Date object
   * 
   * @param date
   *            date
   * @return String
   */
  static public String getTimeStr(Date date) {
    SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
    return format.format(date);
  }

  /**
   * getDateStr get a string with format YYYY-MM-DD from a Date object
   * 
   * @param date
   *            date
   * @return String
   */

  static public String getDateStrByPattern(Date date, String pattern) {
    SimpleDateFormat format = new SimpleDateFormat(pattern);
    return format.format(date);
  }

  static public String getDateStr(Date date) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    return format.format(date);
  }

  static public String getDateStrC(Date date) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日");
    return format.format(date);
  }

  /**
   * getDateStr get a string with format YYYY-MM-DD HH:mm:ss from a Date object
   * 
   * @param date
   *            date
   * @return String
   */
  static public String getDateTimeStr(Date date) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    return format.format(date);
  }

  static public String getDateTimeStrC(Date date) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
    return format.format(date);
  }

  /**
   * Parses text in 'YYYY-MM-DD' format to produce a date.
   * 
   * @param s
   *            the text
   * @return Date
   * @throws java.text.ParseException
   */
  static public Date parseDate(String s) throws ParseException {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    return format.parse(s);
  }

  static public Date parseDateC(String s) throws ParseException {
    SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日");
    return format.parse(s);
  }

  /**
   * Parses text in 'YYYY-MM-DD' format to produce a date.
   * 
   * @param s
   *            the text
   * @return Date
   * @throws java.text.ParseException
   */
  static public Date parseDateTime(String s) throws ParseException {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    return format.parse(s);
  }

  static public Date parseTime(String s) throws ParseException {
    SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
    return format.parse(s);
  }

  static public Date parseDateTimeC(String s) throws ParseException {
    SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
    return format.parse(s);
  }
}
